package com.falcon.service.impl;

import java.util.List;

import com.falcon.domain.dos.ExamAnswerSheetDO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.bean.BeanUtil;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swan.mybatis.condition.Condition;
import com.falcon.mvc.domain.BasePager;
import com.falcon.core.utils.BeanUtils;

import com.falcon.domain.po.ExamAnswerSheetPO;
import com.falcon.domain.req.ExamAnswerSheetQuery;
import com.falcon.domain.req.ExamAnswerSheetRequest;

import com.falcon.mapper.IExamAnswerSheetMapper;
import com.falcon.service.IExamAnswerSheetService;


@Slf4j
@Service
public class ExamAnswerSheetService implements IExamAnswerSheetService {

    @Autowired
    private IExamAnswerSheetMapper examAnswerSheetMapper;

    @Override
    public Long save(ExamAnswerSheetRequest request){
        ExamAnswerSheetPO examAnswerSheetPO = BeanUtil.copyProperties(request, ExamAnswerSheetPO.class);

        this.examAnswerSheetMapper.insertNotNull(examAnswerSheetPO);

        return examAnswerSheetPO.getId();
    }

    @Override
    public Boolean update(Long id, ExamAnswerSheetRequest request){

        ExamAnswerSheetPO examAnswerSheetPO = BeanUtil.copyProperties(request, ExamAnswerSheetPO.class);
        examAnswerSheetPO.setId(id);

        return this.examAnswerSheetMapper.updateNotNull(examAnswerSheetPO);
    }

    @Override
    public Boolean deleteById(Long id) {

        return this.examAnswerSheetMapper.deleteById(id);
    }

    @Override
    public ExamAnswerSheetDO queryById(Long id){

        ExamAnswerSheetPO examAnswerSheetPO = this.examAnswerSheetMapper.selectById(id);

        ExamAnswerSheetDO examAnswerSheetDO = BeanUtil.copyProperties(examAnswerSheetPO, ExamAnswerSheetDO.class);

        return examAnswerSheetDO;
    }


    @Override
    public List<ExamAnswerSheetDO> queryList(ExamAnswerSheetQuery request){

        Condition condition = request.toCondition();

        List<ExamAnswerSheetPO> poList = this.examAnswerSheetMapper.selectList(condition);

        List<ExamAnswerSheetDO> doList = BeanUtil.copyToList(poList, ExamAnswerSheetDO.class);

        return doList;
    }

    @Override
    public BasePager<ExamAnswerSheetDO> queryPager(ExamAnswerSheetQuery request){


        PageInfo<ExamAnswerSheetPO> pageInfo = PageHelper.startPage(request.getPage(), request.getPageSize())
                .doSelectPageInfo(() -> this.examAnswerSheetMapper.selectList(request.toCondition()));

        return BeanUtils.toPager(pageInfo, ExamAnswerSheetDO.class);
    }

    @Override
    public int batchDelete(List<Long> ids) {

        return this.examAnswerSheetMapper.deleteByIds(ids);
    }


}

